/**
 * 
 */
package com.wgo.bpot.common.transport.servicefacade.hessian;

import java.io.IOException;
import java.lang.reflect.Proxy;

import com.caucho.hessian.io.AbstractHessianOutput;
import com.caucho.hessian.io.AbstractSerializer;
import com.caucho.hessian.io.AbstractSerializerFactory;
import com.caucho.hessian.io.Deserializer;
import com.caucho.hessian.io.Serializer;

/**
 * This class stripps of unecesary objects sent to the server. Thus only 
 * information explicitly defined is sent. 
 * 
 * @author petterei
 * @version $Id: TransientTypeSerializerFactory.java,v 1.1 2006-01-23 09:27:22 petterei Exp $
 */
public class TransientTypeSerializerFactory extends AbstractSerializerFactory {

	@Override
	public Serializer getSerializer(Class cl) {
		if (isTransientType(cl)) {
			return (new TransientTypeSerializer());
		}
		return null;
	}
	
	@Override
	public Deserializer getDeserializer(@SuppressWarnings("unused") Class cl) {
//		if (isTransientType(cl)) {
//			return (new TransientTypeDeserializer());
//		}
		return null;
	}
	
	private boolean isTransientType(Class cl) {
		return Proxy.isProxyClass(cl);
//		String simpleName = cl.getName();
//		return DomainProxy.class.isAssignableFrom(cl) || InvocationHandler.class.isAssignableFrom(cl) || simpleName.startsWith("$Proxy");
	}

}

class TransientTypeSerializer extends AbstractSerializer {
	@Override
	public void writeObject(@SuppressWarnings("unused") Object obj, AbstractHessianOutput out) throws IOException {
		out.writeNull();
	}
}
//class TransientTypeDeserializer extends AbstractDeserializer {
//	@Override
//	public Object readMap(@SuppressWarnings("unused") AbstractHessianInput in) {
//		return null;
//	}
//}